package pkg;
/**
 * BomberBoy, CPS240 Term Project - Team A
 * Andrew Osterink, David Bash, Scott Kidder
 * 	
 * This map controls and renders a tile map. Currently very simple as
 * it creates a square tile map of given sizes. 
 */

import java.awt.*;


/**
 * @author Andy
 */
public class Map extends GameComponent{
	
	public final int TILESIZE = 70;
	
	private Tile[][] tiles;
	
	public Map()
	{
		createMap(10,10);
	}
	
	public void createMap(int width,int height)
	{
		tiles = new Tile[width][height];
		//Image img = ResourceManager.getManager().load("Resources/tmpGrass.png");
		Image img = null;
		for(int x = 0;  x < width; x++)
			for(int y = 0; y < height; y++)
			{
				Tile t = new Tile();
				t.setPosition(new Point(x * TILESIZE, y * TILESIZE));
				t.setSize(new Point(TILESIZE,TILESIZE));
				t.setTexture(img);
						
				tiles[x][y] = t;
			}
	}
	
	public void render(Graphics2D g)
	{
		//Render back to front  
		for(int x = 0; x < getWidth(); x++)
			for(int y = getHeight()-1; y >= 0; y--)
			{
				Tile t = tiles[x][y];
				t.render(g);
			}
	}
	
	public Tile getTile(int x,int y)
	{
		if(x < getWidth() && x >= 0 && 
		   y < getHeight() && y >= 0)
			return tiles[x][y];
		return null;
	}
	
	
	//To note: this hasen't been tested yet although im fairly sure its right
	public Tile tileAtPoint(int x,int y)
	{
		int tileX =(int)( x/(double)TILESIZE);
		int tileY = (int) (y / (double)TILESIZE);
	    return getTile(tileX,tileY);
	}
	
	public int getWidth()
	{
		return tiles.length;
	}
	
	public int getHeight()
	{
		return tiles[0].length;
	}

	@Override
	public void initialize() {
		// nothing
		
	}

	@Override
	public void update(float dt) {
		// nothing
	}
}
